草庐IT

JavaScript typeof, null, 和 undefined

全部标签

javascript - 类型错误 : a is null

很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visitthehelpcenter.关闭9年前。我正在使用以下jQueryAjax调用...无论如何它都不起作用。错误:类型错误:a为空这是我的代码:varprefixUrl="autocomplete?action=complete&id=";$('#complete-field').bind('keyup',function(){varurl=prefixUrl+escape($('#complete-field').val());$.aj

javascript - promise - TypeError : Cannot read property 'then' of undefined

我想我只需要另一双眼睛看这个,因为我无法得到我在这里缺少的东西。$scope.checkout=function(form){//somecodeherefunctioncheckoutErrorHandler(error){//somecodehere}functiondisplaySuccessMessage(){$scope.success=true;cartService.emptyCart();}checkoutService.makePayment($scope.payment).then(function(i){//somecodeherecheckoutService.

javascript - 遍历 JSON 数组给出 "undefined"结果

这个问题在这里已经有了答案:Whyisusing"for...in"forarrayiterationabadidea?(28个答案)JavaScriptfor...invsfor(22个答案)关闭7年前。我有一个从AJAX解析的JSON字符串(在responsevar中):JSON{"TheArray":[{"AlmostThere":{"whatWeAreLookingFor":"Hello"}},{"AlmostThere":{"whatWeAreLookingFor":"Goodbye"}}]}正在解析的JSONvarjsonData=JSON.parse(response);

javascript - Enzyme 在浅层渲染的 React 组件上为 prop 返回 null

问题我刚刚开始进行enzyme和react测试。我正在尝试让enzyme与karma和webpack在一个简单的react组件上一起工作。我的问题是包装器上的prop()返回null,我不确定为什么。Greeter.jsimportReactfrom'react';/**Atrivialcomponentweaddedwhiletryingtogetthereacttestingworking**/exportdefaultclassGreeterextendsReact.Component{constructor(props){super(props);this.state={nam

javascript - 开 Jest + 火力地堡 : TypeError: Cannot read property 'defineProperties' of undefined

我目前正在做一个ReactNative项目,想使用FirebaseJSSDK。为了熟悉它的所有API,我想用Jest编写一些学习测试。这是我的测试:importFirebasefrom'firebase';describe('Firebase',function(){it('shouldwork',function() {expect(null).toBeNull()})});不幸的是我收到了这个错误:●测试套件运行失败TypeError:Cannotreadproperty'defineProperties'ofundefinedatnode_modules/firebase/app

javascript - 为什么 typescript 不提示某些 undefined variable

我有以下示例:classUncle{constructor(publicname:string){}talk(){return"Hellomynameis"+name;}}letp:Uncle=newUncle("Jo");console.log(p.talk());对于某些变量名,typescript(目前版本2.1.4)不会提示它们没有在您的程序中定义(在方法讨论中,名称是在没有这个的情况下使用。)。name就是其中之一。如果我将变量重命名为firstName,编译器会正确地提示...errorTS2663:Cannotfindname'firstName'.Didyoumeant

javascript - Vuex + VueJS : Passing computed property to child is undefined

我正在阅读这个documentationonVuecomponents,但使用Vuex数据作为我的组件属性。在这个例子中,如果country_id在data方法中,它工作正常。但是当country_id是一个从Vuexstore返回数据的计算属性时,子组件的internalValue总是被初始化为undefined。我做错了什么?父组件:exportdefault{computed:{country_id(){returnthis.$store.state.user.country_id}},mounted:function(){this.$store.dispatch('user/l

javascript - IE8 上的 jquery(null 为 null 或不是对象)错误

当我加载jquery时使用:它适用于IE9、firefox、chrome、safari,但不适用于IE8。我尝试了开发者/调试器工具,但仍然不明白为什么这是个问题。这是jquery应该有错误的字符代码:32039。在那条线上有这样的功能:G=function(a){varb=F.exec(a);b&&(b[1]=(b[1]||"").toLowerCase(),b[3]=b[3]&&newRegExp("(?:^|\\s)"+b[3]+"(?:\\s|$)"));returnb}有人也遇到过这个问题吗?站点是http://www.kanersan.com我不会在加载jquery之前调用

javascript - 未捕获的类型错误 : Object prototype may only be an Object or null on ember-1. 0.0-pre.2

我从Ember开始,紧跟着这个tutorial.我从Ember.js网站下载了最后一个源代码,我有以下代码:HTMLTestapp.jsApp=Em.Application.create();App.ApplicationView=Em.View.extend({templateName:'application'});App.ApplicationController=Em.Controller.extend();App.Router=Em.Router.extend({root:Em.Route.extend({index:Em.Route.extend({route:'/'})}

javascript - JavaScript 中全局作用域中存在 undefined variable 的原因是什么?

我发现很多关于undefined作为值的讨论,例如如何检查是否相等等等。但是undefined作为全局变量存在的“工程”原因是什么?对面没有null变量...console.log(undefinedinthis);//logstrueconsole.log(nullinthis);//logsfalse 最佳答案 在JavaScript中,null是一个保留字;undefined不是,但由环境实现作为一个全局变量,其值为undefined。您会注意到您可以更改undefined的值,但不能更改null的值,except严格模式(会